﻿using DataGridView.Models;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DataGridView.ViewModels;
using FreeSql;

namespace DataGridView
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml with MVC
    /// </summary>
    public partial class MainWindow : Window
    {
        //private List<Employee> employees;
        //private ICollectionView collectionView;
        public MainWindow()
        {
            InitializeComponent();
            DataContext = new MainWindowViewModel();
            
            /*var fsql = new FreeSqlBuilder()
                .UseConnectionString(DataType.Sqlite,"DataSource=demo.db")
                .UseAutoSyncStructure(true)
                .Build();
            fsql.CodeFirst.SyncStructure<Employee>();
            fsql.Insert<Employee>(Employee.FakeMany(100)).ExecuteAffrows();*/


            //employees =new List<Employee>(Employee.FakeMany(10));
            //collectionView = CollectionViewSource.GetDefaultView(employees);
            //dataGrid.ItemsSource = employees;
            //collectionView.Filter = (object item) =>
            //{
            //    var em = (Employee)item;
            //    return em.FirstName.Contains(filterTextBox.Text) || em.LastName.Contains(filterTextBox.Text);
            //};
            //var cvs = this.FindResource("DataGridView") as CollectionViewSource;
            //cvs.Source = employees;
        }

        //private void CollectionViewSource_Filter(object sender, FilterEventArgs e)
        //{
        //    var em = e.Item as Employee;
        //    var text = filterTextBox.Text;
        //    e.Accepted = em.FirstName.Contains(text) || em.LastName.Contains(text);
        //}

        /*private void filterTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            //CollectionViewSource.GetDefaultView(dataGrid.ItemsSource).Refresh();
            collectionView.Refresh();
        }
        private void AddNewEmployee(object sender, RoutedEventArgs e)
        {
            employees.Add(Employee.FakeOne());
            //CollectionViewSource.GetDefaultView(dataGrid.ItemsSource).Refresh();
            collectionView.Refresh();
        }*/
    }
}